<?
session_start();
if(!isset($_SESSION['userName']))
	exit();

$pageWidth = 80;
$pageHeader = 50;
$lineSeparator = 5;

require("includes/funciones.inc.php");
require("includes/constants.php");
require("includes/selectLanguage.php");
require('includes/fpdf/fpdf.php');

$DB = NewADOConnection('mysqlt');
$DB->Connect();
$DB->Execute("SET NAMES utf8;");
//$DB->debug=true;

$idTable = $_REQUEST["idTable"];

$strSQL = "SELECT tables.description, users.userCompleteName FROM tables 
			INNER JOIN assignedtables ON tables.idTable = assignedtables.idTable 
			INNER JOIN users ON assignedtables.idUser = users.idUser 
			WHERE tables.idTable=".$idTable;
$rsTable = $DB->Execute($strSQL);

$strSQL = "SELECT description, quantity, orderfooditem.price FROM food 
			INNER JOIN orderfooditem ON food.idFood = orderfooditem.idFood 
			INNER JOIN orderfood ON orderfood.idOrderFood = orderfooditem.idOrderFood 
			WHERE orderfood.idTable = ".$idTable." AND orderfood.state = '".$stateTableBusy."' AND orderfooditem.quantity > 0 AND orderfood.idRestaurant = ".$_SESSION['userRestaurant'];
$rsTableState = $DB->Execute($strSQL);

$pdf = new FPDF();

$orderLine = $rsTableState->RecordCount() * $lineSeparator;

$pdf->AddPage('P', array($pageWidth,$pageHeader+$orderLine));
$pdf->SetFont('Arial','B',10);

$pdf->Cell(40,5,$a_languages['TicketPDF.Date'].date("d/m/Y"),0,1);
$pdf->Cell(40,5,$a_languages['TicketPDF.Table'].$rsTable->fields(0),0,1);
$pdf->Cell(40,5,$a_languages['TicketPDF.YoungMan'].$rsTable->fields(1),0,1);
$pdf->Line(5,25,205,25);

//Make Order Items
$pdf->SetFont('Arial','',6);
while(!$rsTableState->EOF){
	$pdf->Cell(3,4,$rsTableState->fields(1),0,0,'R');
	$pdf->Cell(150,4,$rsTableState->fields(0),0,0);
	$pdf->Cell(0,4,'$ '.number_format($rsTableState->fields(2),2),0,1,'R');
	
	$total += $rsTableState->fields(2);
	$rsTableState->MoveNext();
}
$pdf->ln();
$pdf->SetFont('Arial','B',10);
$pdf->Cell(0,5,$a_languages['TicketPDF.Total'].'$ '.number_format($total,2),0,0,'R');

$pdf->Output();

?>